package com.jsoft.service.impl;

import com.jsoft.dao.EnterpriseDao;
import com.jsoft.dao.impl.EnterpriseDaoImpl;
import com.jsoft.entity.Enterprise;
import com.jsoft.service.EnterpriseService;

import java.util.List;
import java.util.Objects;

/**企业表的服务层
 * @author snkstart
 * @create 2023-02-20 20:27
 */
public class EnterpriseServiceImpl implements EnterpriseService {
    private EnterpriseDao enterpriseDao = new EnterpriseDaoImpl();

    @Override
    public List<Enterprise> selectEnterprise() {
        List<Enterprise> enterprises = null;
        try {
            enterprises = enterpriseDao.selectEnterprise();
                for (int i = 0; i < enterprises.size(); i++) {
                    int id = enterprises.get(i).getId();
                    String name = enterprises.get(i).getName();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return enterprises;
    }

    @Override
    public String selectCode(String EnterpriseName) {
        String EnterpriseId = "";
        try {
            EnterpriseId = enterpriseDao.selectEnterpriseCodeByName(EnterpriseName);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return EnterpriseId;
    }


    /**
     * 根据企业id查询企业名和社会统一代码
     * @param id 企业id
     * @return 返回企业名和社会统一代码
     * @throws Exception 将所有异常抛到controller层
     */
    @Override
    public Enterprise findEnterpriseById(Integer id) throws Exception {
        return enterpriseDao.findEnterpriseById(id);
    }

}
